package com.nanbei.doublepoint;

import java.util.Arrays;

/**
 * @ClassDescription: 两数之和（双指针）
 * @JdkVersion: 1.8
 * @Author: libs
 * @Created: 2024/7/16 15:41
 */
public class TwoSumIiInputArrayIsSorted {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(twoSum(new int[]{2, 7, 11, 15}, 9)));
    }

    /**
     *
     * @param numbers 有序数组
     * @param target 目标值
     * @return 计算两个数字的下标
     */
    public static int[] twoSum(int[] numbers, int target) {
        int length = numbers.length;
        int max =length-1;
        int min = 0;

        while (min<max){
            if (numbers[max] + numbers[min] <target){
                min++;
            }else if (numbers[max] + numbers[min] >target){
                max--;
            }else {
                break;
            }
        }


        return new int[]{min,max};
    }
}
